package com.yxy.chatserver.mapper;

import com.yxy.chatserver.domain.po.BaseMessage;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface MessageMapper {
    /**
     * 保存消息
     * @param baseMessage
     */
    void save(BaseMessage baseMessage);

    /**
     * 获取未读消息
     * @param userId
     * @return
     */
    @Select("select * from messages where to_user_id = #{userId} and status = 'sent'")
    List<BaseMessage> getUnreadMessages(String userId);

    /**
     * 更新消息状态
     * @param messageId
     * @param received
     */
    @Select("update messages set status = #{received} where id = #{messageId}")
    void updateStatusById(String messageId, String received);
}
